Clarify third party subcommand failure error message
authorBoris Egorov <egorov@linux.com>
Tue, 23 Feb 2016 17:44:54 +0000 (23:44 +0600)
committerBoris Egorov <egorov@linux.com>
Wed, 24 Feb 2016 10:08:17 +0000 (16:08 +0600)
Fixes #2378

src/bin/cargo.rs
tests/test_cargo_install.rs

index 350448df0ad6da86467be23df36d244a6cbc0810..9011ca1fe599ee1a45a74bcaacd7bbd757a97ec6 100644 (file)
@@ -11,7 +11,7 @@ use std::fs;
 use std::path::PathBuf;
 
 use cargo::execute_main_without_stdin;
-use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult};
+use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult, ChainError};
 
 #[derive(RustcDecodable)]
 pub struct Flags {
@@ -205,7 +205,9 @@ fn execute_subcommand(config: &Config,
             }))
         }
     };
-    try!(util::process(&command).args(&args[1..]).exec());
+    try!(util::process(&command).args(&args[1..]).exec().chain_error(|| {
+        human(format!("third party subcommand `{}` exited unsuccessfully", command_exe))
+    }));
     Ok(())
 }
 
index db00ef614fb8600dc826465238ac2fd66bc6c9cc..2b54f940e48aba5aa6403fae89e8117eae5491b7 100644 (file)
@@ -568,3 +568,25 @@ be sure to add `[..]` to your PATH to be able to run the installed binaries
     assert!(p.release_bin("foo").c_exists());
     assert_that(cargo_home(), has_installed_exe("foo"));
 });
+
+test!(reports_unsuccessful_subcommand_result {
+    Package::new("cargo-fail", "1.0.0")
+        .file("src/main.rs", r#"
+            fn main() {
+                panic!();
+            }
+        "#)
+        .publish();
+    assert_that(cargo_process("install").arg("cargo-fail"),
+                execs().with_status(0));
+    assert_that(cargo_process("--list"),
+                execs().with_status(0).with_stdout_contains("  fail\n"));
+    assert_that(cargo_process("fail"),
+                execs().with_status(101).with_stderr_contains("\
+thread '<main>' panicked at 'explicit panic', [..]
+").with_stderr_contains("\
+third party subcommand `cargo-fail[..]` exited unsuccessfully
+
+To learn more, run the command again with --verbose.
+"));
+});